package tuiLayer;



import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import controlLayer.*;
import modelLayer.*;
/**
 * The test class TuiTest.
 *
 * @author  (your name)
 * @version (a version number or a date)
 */
public class TuiTest
{
    /**
     * Default constructor for test class TuiTest
     */
    public TuiTest()
    {
    }

    /**
     * Sets up the test fixture.
     *
     * Called before every test case method.
     */
    @Before
    public void setUp()
    {
    }

    /**
     * Tears down the test fixture.
     *
     * Called after every test case method.
     */
    @After
    public void tearDown()
    {
    }
    
    @Test
    public void CrudDVDTest()
    {
        tuiLayer.DVDUI dVDUI1 = new tuiLayer.DVDUI();
        // Create
        dVDUI1.createDVD("TestBarcode1.0", "TestTitle1.0", "TestArtist1.0", "TestPubDate1.0", 1.0);
        // Find
        assertNotNull(dVDUI1.findDVD("TestBarcode1.0"));              
        // Update
        dVDUI1.createDVD("TestBarcode2.0", "TestTitle2.0", "TestArtist2.0", "TestPubDate2.0", 2.0);
        DVD dvd1 = dVDUI1.findDVD("TestBarcode2.0");  
        dVDUI1.updateDVD(dvd1,"TestBarcode2.1", "TestTitle2.1", "TestArtist2.1", "TestPubDate2.1", 2.1);
        // Delete
        dVDUI1.createDVD("TestBarcode3.0", "TestTitle3.0", "TestArtist3.0", "TestPubDate3.0", 3.0);
        dVDUI1.deleteDVD(dVDUI1.findDVD("TestBarcode3.0"));
    }
    
    @Test
    public void CrudPersonTest()
    {
        tuiLayer.PersonUI personUI1 = new tuiLayer.PersonUI();
        // Create
        personUI1.createPerson("TestCpr1.0", "TestName1.0", "TestAddress1.0", "TestPostalCode1.0", "TestCity1.0","TestPhone1.0");
        // Find
        assertNotNull(personUI1.findPerson("TestCpr1.0"));
        // Update
        personUI1.createPerson("TestCpr2.0", "TestName2.0", "TestAddress2.0", "TestPostalCode2.0", "TestCity2.0","TestPhone2.0");
        Person person1 = personUI1.findPerson("TestCpr2.0");
        personUI1.updatePerson(person1,"TestCpr2.1", "TestName2.1", "TestAddress2.1", "TestPostalCode2.1", "TestCity2.1","TestPhone2.1");
        // Delete
        personUI1.createPerson("TestCpr3.0", "TestName3.0", "TestAddress3.0", "TestPostalCode3.0", "TestCity3.0","TestPhone3.0");
        personUI1.deletePerson(personUI1.findPerson("TestCpr3.0"));
    }
    
    @Test
    public void CrudLoanTest()
    {
        tuiLayer.LoanUI loanUI1 = new tuiLayer.LoanUI();
        tuiLayer.DVDUI dVDUI1 = new tuiLayer.DVDUI();
        tuiLayer.PersonUI personUI1 = new tuiLayer.PersonUI();
        
        // Create
        
        dVDUI1.createDVD("BarcodeForCopy","TitleForCopy", "ArtistForCopy","PubDateForCopy", 111.11);
        dVDUI1.createCopy(dVDUI1.findDVD("BarcodeForCopy"),"TestSerialNumber","TestPurchaseDate");
        Copy copy1 = dVDUI1.findCopy(dVDUI1.findDVD("BarcodeForCopy"),"TestSerialNumber");
        personUI1.createPerson("CprForLoan","NameForLoan", "AddressForLoan", "PostalCodeForLoan","CityForLoan","PhoneForLoan");
        Person person1 = personUI1.findPerson("CprForLoan");
        loanUI1.createLoan(copy1,person1,"TestId1.0", "TestBorrowDate1.0", "TestPeriod1.0", "TestState1.0");
        
        // Find
               
        assertNotNull(loanUI1.findLoan("TestId1.0"));
        
        // Update
        loanUI1.createLoan(copy1,person1,"TestId2.0", "TestBorrowDate2.0", "TestPeriod2.0","TestState2.0");
        Loan loan1 = loanUI1.findLoan("TestId2.0");
        loanUI1.updateLoan(loan1,"TestPeriod2.1");
        
        // Delete
        loanUI1.createLoan(copy1,person1,"TestId3.0", "TestBorrowDate3.0", "TestPeriod3.0", "TestState3.0");
        loanUI1.deleteLoan(loanUI1.findLoan("TestId3.0"));
    }
}
